const domainName = getApp().globalData.domainName
const header = {'content-type':'application/x-www-form-urlencoded'}
const dataType = 'json'
const method = 'POST'
const responseType = 'text'


  // 上传数据
const edit_ti=(that)=>{
    // console.log('上传数据')
    wx.request({
      url: domainName + '/edit_ti_submit',
      data: {
        ti_info:JSON.stringify(that.data.ti_info),
      },
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        let res_data = res.data
        if(res_data.update_res){
          wx.showToast({
            title: '提交完成',
            duration: 1500,
            icon: 'success',
          })
        }
      },
    })
    
  }




  // 查询类似的习题列表
const search_ti_list=(that,question)=>{
    wx.request({
      url: domainName + '/search_ti_list',
      data: {
        input_q:question
      },
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        that.setData({
          ti_list:res.data.ti_list || [],
        })
      },
    })
  }



  // 加载习题信息
const page_init=(that,ti_id)=>{
    wx.request({
      url: domainName + '/edit_load_ti_info',
      data: {
        ti_id:ti_id,
      },
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        // console.log('加载习题信息',res.data)
        that.setData({
          ti_info:res.data.ti_info,
          chap_list:res.data.chap_list,
        })
      },
    })
  }


  module.exports={
    edit_ti:edit_ti,
    search_ti_list:search_ti_list,
    page_init:page_init,
  }